package controllers

import (
	"gdshop-font-api-go/app/request/UserRequest"
	"gdshop-font-api-go/app/service/UserService"
	"gdshop-font-api-go/library/response"
	toolsJwt "gdshop-font-api-go/library/tools/jwt"
	"github.com/gogf/gf/net/ghttp"
)

type TestController struct {
	*BaseController
}

func (c *TestController) Index(r *ghttp.Request) *response.JsonResponse {
	return response.FailByRequestMessage(r, "test")

	/*
		user := toolsDb.GetUnSafaTableAddDeleteWhere("Member")
		//UserResponse.Where("delete_at < ?", 1)
		userList := ([]UserResponse.List)(nil)
		err := user.Structs(&userList)
		if err != nil {
			return response.FailByRequestMessage(r, err.Error())
		} else {
			return response.SuccessByRequestMessageData(r, "成功", userList)
		}
	*/
}

func (c *TestController) Add(r *ghttp.Request) *response.JsonResponse {
	var parames *UserRequest.Add
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return UserService.Add(r.GetCtx(), parames)
}

func (c *TestController) Test(r *ghttp.Request) *response.JsonResponse {
	tokenString := r.GetString("t")

	memberId := toolsJwt.VerifyLoginToken(tokenString)
	if memberId < 1 {
		return response.FailByRequestMessage(r, "验证失败")
	}
	return response.SuccessByRequestMessageData(r, "成功", memberId)
}
